<!DOCTYPE html>
<html lang="zh-cn,en,default">
<head>
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.0.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('http://yoursite.com').hostname,
    root: '/',
    scheme: 'Pisces',
    version: '7.5.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
    copycode: {"enable":true,"show_result":true,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.json',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    sidebarPadding: 40
  };
</script>

  <meta name="description" content="红黑树 我们都知道平衡二叉查找树（排序树）在极端情况下，查询效率为O(N)。因此需要一个自平衡的数据结构保证查找效率。本片主角红黑树树就这样诞生了。  红黑树（英语：Red–black tree）是一种自平衡二叉查找树，是在计算机科学中用到的一种数据结构，典型的用途是实现关联数组。它在1972年由鲁道夫·贝尔发明，被称为&amp;quot;对称二叉B树&amp;quot;，它现代的名字源于Leo J. Guib">
<meta name="keywords" content="数据结构">
<meta property="og:type" content="article">
<meta property="og:title" content="红黑树">
<meta property="og:url" content="http:&#x2F;&#x2F;yoursite.com&#x2F;2019&#x2F;11&#x2F;24&#x2F;%E7%BA%A2%E9%BB%91%E6%A0%91&#x2F;index.html">
<meta property="og:site_name" content="子我">
<meta property="og:description" content="红黑树 我们都知道平衡二叉查找树（排序树）在极端情况下，查询效率为O(N)。因此需要一个自平衡的数据结构保证查找效率。本片主角红黑树树就这样诞生了。  红黑树（英语：Red–black tree）是一种自平衡二叉查找树，是在计算机科学中用到的一种数据结构，典型的用途是实现关联数组。它在1972年由鲁道夫·贝尔发明，被称为&amp;quot;对称二叉B树&amp;quot;，它现代的名字源于Leo J. Guib">
<meta property="og:locale" content="zh-cn">
<meta property="og:image" content="https:&#x2F;&#x2F;blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com&#x2F;%E7%BA%A2%E9%BB%91%E6%A0%91.png">
<meta property="og:image" content="https:&#x2F;&#x2F;blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com&#x2F;rotationLeft.gif">
<meta property="og:image" content="https:&#x2F;&#x2F;blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com&#x2F;rotationRight.gif">
<meta property="og:image" content="https:&#x2F;&#x2F;blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com&#x2F;%E7%BA%A2%E9%BB%91%E6%A0%91%E6%8F%92%E5%85%A51.png">
<meta property="og:image" content="https:&#x2F;&#x2F;blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com&#x2F;%E7%BA%A2%E9%BB%91%E6%A0%91%E6%8F%92%E5%85%A5%202.1.png">
<meta property="og:image" content="https:&#x2F;&#x2F;blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com&#x2F;%E7%BA%A2%E9%BB%91%E6%A0%91%E6%8F%92%E5%85%A5%202.2.png">
<meta property="og:image" content="https:&#x2F;&#x2F;blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com&#x2F;%E7%BA%A2%E9%BB%91%E6%A0%91%E5%88%A0%E9%99%A4%201.png">
<meta property="og:image" content="https:&#x2F;&#x2F;blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com&#x2F;%E7%BA%A2%E9%BB%91%E6%A0%91%E5%88%A0%E9%99%A4%202.png">
<meta property="og:image" content="https:&#x2F;&#x2F;blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com&#x2F;%E7%BA%A2%E9%BB%91%E6%A0%91%E5%88%A0%E9%99%A4%203.png">
<meta property="og:image" content="https:&#x2F;&#x2F;blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com&#x2F;%E7%BA%A2%E9%BB%91%E6%A0%91%E5%88%A0%E9%99%A44.png">
<meta property="og:image" content="https:&#x2F;&#x2F;blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com&#x2F;%E7%BA%A2%E9%BB%91%E6%A0%91%E5%88%A0%E9%99%A45.png">
<meta property="og:updated_time" content="2019-11-24T09:41:48.129Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https:&#x2F;&#x2F;blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com&#x2F;%E7%BA%A2%E9%BB%91%E6%A0%91.png">

<link rel="canonical" href="http://yoursite.com/2019/11/24/%E7%BA%A2%E9%BB%91%E6%A0%91/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true,
    isPage: false,
    isArchive: false
  };
</script>

  <title>红黑树 | 子我</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript><!-- hexo-inject:begin --><link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/katex.min.css'><!-- hexo-inject:end -->

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">子我</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">子我的原创IT技术博客</p>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>Home</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>Tags</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>Categories</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>Archives</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>Search
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="none"
           placeholder="Searching..." spellcheck="false"
           type="text" id="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/cyrilney" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-cn">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/11/24/%E7%BA%A2%E9%BB%91%E6%A0%91/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com/avatar.jpg">
      <meta itemprop="name" content="Cyril Nee">
      <meta itemprop="description" content="站在巨人的肩膀上。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="子我">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          红黑树
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2019-11-24 03:03:05 / Modified: 17:41:48" itemprop="dateCreated datePublished" datetime="2019-11-24T03:03:05+08:00">2019-11-24</time>
            </span>

          
            <span class="post-meta-item" title="Views" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">Views: </span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine: </span>
    
    <a title="valine" href="/2019/11/24/%E7%BA%A2%E9%BB%91%E6%A0%91/#comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2019/11/24/%E7%BA%A2%E9%BB%91%E6%A0%91/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="红黑树"><a class="markdownIt-Anchor" href="#红黑树"></a> 红黑树</h2>
<p>我们都知道平衡二叉查找树（排序树）在极端情况下，查询效率为O(N)。因此需要一个自平衡的数据结构保证查找效率。本片主角红黑树树就这样诞生了。</p>
<blockquote>
<p>红黑树（英语：Red–black tree）是一种自平衡二叉查找树，是在计算机科学中用到的一种数据结构，典型的用途是实现关联数组。它在1972年由鲁道夫·贝尔发明，被称为&quot;对称二叉B树&quot;，它现代的名字源于Leo J. Guibas和Robert Sedgewick于1978年写的一篇论文。红黑树的结构复杂，但它的操作有着良好的最坏情况运行时间，并且在实践中高效：它可以在log n时间内完成查找，插入和删除，这里的n是树中元素的数目.</p>
<p>—— 摘自wiki对红黑树的介绍</p>
</blockquote>
<h3 id="性质"><a class="markdownIt-Anchor" href="#性质"></a> 性质</h3>
<p>红黑树是一颗查询复杂度保持在O(log N) 的自平衡二叉查找树。在原有的二叉查找树的性质下，通过给节点上色满足如下性质实现：</p>
<ul>
<li><strong>节点是红色或黑色。</strong></li>
<li><strong>根是黑色。</strong></li>
<li><strong>所有叶子都是黑色（叶子节点指NIL节点）。</strong></li>
<li><strong>每个红色节点必须有两个黑色的子节点。（从每个叶子到根的所有路径上不能有两个连续的红色节点。）</strong></li>
<li><strong>从任一节点到其每个叶子的所有简单路径都包含相同数目的黑色节点。</strong></li>
</ul>
<p>具体的某个红黑树入大概入下图所示。 注意<strong>任何红黑树都要满足上面五条性质。</strong></p>
<p><img src="https://blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com/%E7%BA%A2%E9%BB%91%E6%A0%91.png" alt="" /></p>
<h3 id="操作"><a class="markdownIt-Anchor" href="#操作"></a> 操作</h3>
<p>红黑树的操作包括新增、删除、和查询操作。 查询操作与之前的二叉树查找树雷同，这里略过。额外地，需要说明一下二叉查找树中的旋转操作</p>
<h4 id="旋转"><a class="markdownIt-Anchor" href="#旋转"></a> 旋转</h4>
<p>二叉排序树的旋转指的是不破坏二叉树性质的情况下，改变树的结构的一种操作。具体分为如下两种操作：</p>
<ul>
<li>左旋， 将树进行逆时针旋转。如图所示，节点E进行左旋，原本E的右子树接替E的位置称为父亲，E成为S节点的左孩子。注意如果S原本有左子树（左子树的值应该在E到S之间），将该树称为E的新右儿子。仍然满足二叉排序树的规则：</li>
</ul>
<p><img src="https://blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com/rotationLeft.gif" alt="" /></p>
<ul>
<li>右旋，将树进行顺时针旋转。左旋的镜像操作。如图所示：</li>
</ul>
<p><img src="https://blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com/rotationRight.gif" alt="" /></p>
<p>注意，旋转是满足二叉排序树的结构变化操作。 旋转后的节点高度可能会发生变化。 红黑树而言，可能会导致与其性质冲突。 因此需要再对红黑树进行重染色。</p>
<h4 id="新增"><a class="markdownIt-Anchor" href="#新增"></a> 新增</h4>
<p>红黑树新增时，默认新增的是红色节点。一种情况是，如果节点是根结点，则将树染红即可；一种简单的情况是，当节点的父亲是黑色节点时显然不会违反之前的规则。当父亲节点是红色节点时。需要分情况讨论。</p>
<ol>
<li>
<p>当节点的叔叔节点（父亲节点的兄弟节点）是红色时。 将父亲节点和叔叔节点染黑，将爷爷节点染红。这样操作后，所有经过父亲节点和叔叔节点黑色节点数不变，满足<strong>性质5</strong>，但爷爷节点染红后可能会导致它其与上层节点的冲突。因此当前指针指向爷爷节点，重新进行一次判断。<br />
<img src="https://blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com/%E7%BA%A2%E9%BB%91%E6%A0%91%E6%8F%92%E5%85%A51.png" alt="" /></p>
</li>
<li>
<p>当前节点的叔叔节点为黑色时，分如下两种情况来讨论（这里以父亲节点为左子树来判断，若是右子树则镜像操作即可）</p>
<ol>
<li>
<p>当前节点是父亲节点的左子树。 则将父亲节点染黑，爷爷节点染红。 再对爷爷进行右旋操作。 此时经过父亲节点的节点和黑节点数不变（满足<strong>性质5</strong>）。<br />
<img src="https://blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com/%E7%BA%A2%E9%BB%91%E6%A0%91%E6%8F%92%E5%85%A5%202.1.png" alt="" /></p>
</li>
<li>
<p>当前节点是父亲节点的右子树。则将父亲节点进行左旋，当前指针指向原来的父节点。此时当前节点变为父亲节点的左子树。 按照 2.1 的方式处理。<br />
<img src="https://blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com/%E7%BA%A2%E9%BB%91%E6%A0%91%E6%8F%92%E5%85%A5%202.2.png" alt="" /></p>
</li>
</ol>
</li>
</ol>
<h4 id="删除"><a class="markdownIt-Anchor" href="#删除"></a> 删除</h4>
<p>删除操作比较复杂。 大概跟味两部分：删除流程和删除节点后平衡操作。</p>
<h5 id="删除流程"><a class="markdownIt-Anchor" href="#删除流程"></a> 删除流程</h5>
<p>首先通过二分操作找到需要删除的节点。根据当前节点判断是否能删除：</p>
<ol>
<li>如果被删除节点有两个孩子：直接寻找该节点的中序后继（即右子树中最小的节点）。后继节点的值覆盖当前节点值。指针指向后继重新进行判断。</li>
<li>如果被删除节点有一个孩子或孩子都为 NIL：则继续进行判断</li>
<li>如果被删除节点是红色节点：直接将孩子节点顶替当前节点。不会影响到性质。</li>
<li>如果被删除节点是黑色节点，且其孩子节点为红色：将孩子节点顶替当前节点，再讲孩子节点染黑即可。</li>
<li>如果被删除节点是黑色节点，且孩子节点都为黑色（此时孩子节点必为NIL节点，否则单独节点为黑色不满足性质5）：当时情况较为复杂，则进行以下删除后平衡操作。</li>
</ol>
<h5 id="删除后平衡操作"><a class="markdownIt-Anchor" href="#删除后平衡操作"></a> 删除后平衡操作</h5>
<p>首先是如果当前节点已经是根结点了，则将根结点染黑。</p>
<p>我们将删除前的节点定义为N（先平衡，再删除替换节点），节点的父节点为P， 兄弟节点为S，兄弟节点的左子树为SL，右子树为SR。我们遍历N、P、S、SL、SR可能有的情况有如下几种，我们将主意进行讨论。（下文将由N节点为P节点的左子树进行讨论。若为右子树，镜像操作即可）</p>
<table>
<thead>
<tr>
<th>N</th>
<th>P</th>
<th>S</th>
<th>SL</th>
<th>SR</th>
<th>case</th>
</tr>
</thead>
<tbody>
<tr>
<td>B</td>
<td>S</td>
<td>B</td>
<td>B(NIL)</td>
<td>B(NIL)</td>
<td>(1)</td>
</tr>
<tr>
<td>B</td>
<td>B</td>
<td>B</td>
<td>B(NIL)</td>
<td>B(NIL)</td>
<td>(2)</td>
</tr>
<tr>
<td>B</td>
<td>B</td>
<td>S</td>
<td>B</td>
<td>B</td>
<td>(3)</td>
</tr>
<tr>
<td>B</td>
<td>B(or S)</td>
<td>B</td>
<td>S</td>
<td>B(NIL)</td>
<td>(4)</td>
</tr>
<tr>
<td>B</td>
<td>B(or S)</td>
<td>B</td>
<td>S(or B(NIL))</td>
<td>S</td>
<td>(5)</td>
</tr>
</tbody>
</table>
<ol>
<li>
<p>删除节点为黑色， 父亲节点为红色， S节点为黑色， 且S节点的孩子SL、SR都为黑色（NIL节点）。 则将P节点染黑，S节点染红。则经过S节点的黑色节点数不变。经过N的黑色节点数补齐。满足相关性质。<br />
<img src="https://blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com/%E7%BA%A2%E9%BB%91%E6%A0%91%E5%88%A0%E9%99%A4%201.png" alt="" /></p>
</li>
<li>
<p>删除节点为黑色， 父亲节点为黑色， S节点为黑色， 且S节点的孩子SL、SR都为黑色（NIL节点）。将S节点染红。此时通过N节点和通过S节节点，即通过P的比删除前少1。将当前指针指向P节点，重新执行平衡操作。<br />
<img src="https://blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com/%E7%BA%A2%E9%BB%91%E6%A0%91%E5%88%A0%E9%99%A4%202.png" alt="" /></p>
</li>
<li>
<p>删除节点为黑色，父亲节点为黑色，S节点为红色，则S节点的孩子SL、SR都为黑色。将P节点染红，S节点染黑，再对叶子节点进行左旋。此时经过S节点的数量不变。经过N的节点仍然少1，此时P为红色。按照情况4、5进行判断。<br />
<img src="https://blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com/%E7%BA%A2%E9%BB%91%E6%A0%91%E5%88%A0%E9%99%A4%203.png" alt="" /></p>
</li>
<li>
<p>删除节点为黑色，父亲节点为红色或者为黑色，S节点为黑色，其左SL节点为红色，右节点为黑色（为NIL）。将SL染黑，S染红，S节点右旋。这样S和SL角色互换，可以按照情况5判断。<br />
<img src="https://blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com/%E7%BA%A2%E9%BB%91%E6%A0%91%E5%88%A0%E9%99%A44.png" alt="" /></p>
</li>
<li>
<p>删除节点为黑色，父亲节点为红色或者黑色，S节点为黑色。其右子树SR为红色（SL为红色或黑（NIL））。S节点染为P节点的颜色，P节点染黑，SR节点染黑，P节点左旋。 此时SR节点不变， SL节点和N节点恢复。满足规律5。恢复平衡。<br />
<img src="https://blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com/%E7%BA%A2%E9%BB%91%E6%A0%91%E5%88%A0%E9%99%A45.png" alt="" /></p>
</li>
</ol>
<h3 id="证明"><a class="markdownIt-Anchor" href="#证明"></a> 证明</h3>
<p>我们在之前说过红黑树的查询效率是log2(n)。但具体为什么根据前面5条性质即确定红黑树的具体查询效率的呢？需要进行证明：</p>
<p>首先定义 BH(v) 为节点黑色高度（ 红黑树的节点v上到他的叶子节点的黑色节点的个数，不计v本身）、TOTAL[ BH(v) ] 为 当黑高为 BH(v 时，树可能有的总叶子节点个数 可知</p>
<ol>
<li>
<p>BH(v) = 0 时 v 此时可能为空节点或只有v本身 、TOTAL[ BH(v) ] 最小为 0</p>
</li>
<li>
<p>当 BH(v) &gt; 0 时： 根据 <strong>性质5</strong> 黑高为 BH(V) 的 红黑树， 其子树的黑高至少为 BH(V) - 1 （或子树的高度仍为 BH(V) ）即数的节点总数</p>
</li>
</ol>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>T</mi><mi>O</mi><mi>T</mi><mi>A</mi><mi>L</mi><mo stretchy="false">[</mo><mi>B</mi><mi>H</mi><mo stretchy="false">(</mo><mi>v</mi><mo stretchy="false">)</mo><mo stretchy="false">]</mo><mo>≥</mo><mn>2</mn><mo>⋅</mo><mi>T</mi><mi>O</mi><mi>T</mi><mi>A</mi><mi>L</mi><mo stretchy="false">[</mo><mi>B</mi><mi>H</mi><mo stretchy="false">(</mo><mi>v</mi><mo stretchy="false">)</mo><mo>−</mo><mn>1</mn><mo stretchy="false">]</mo><mo>+</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">TOTAL[BH(v)] \geq 2 \cdot TOTAL[BH(v) - 1] + 1
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathdefault" style="margin-right:0.13889em;">T</span><span class="mord mathdefault" style="margin-right:0.02778em;">O</span><span class="mord mathdefault" style="margin-right:0.13889em;">T</span><span class="mord mathdefault">A</span><span class="mord mathdefault">L</span><span class="mopen">[</span><span class="mord mathdefault" style="margin-right:0.05017em;">B</span><span class="mord mathdefault" style="margin-right:0.08125em;">H</span><span class="mopen">(</span><span class="mord mathdefault" style="margin-right:0.03588em;">v</span><span class="mclose">)</span><span class="mclose">]</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≥</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">2</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">⋅</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathdefault" style="margin-right:0.13889em;">T</span><span class="mord mathdefault" style="margin-right:0.02778em;">O</span><span class="mord mathdefault" style="margin-right:0.13889em;">T</span><span class="mord mathdefault">A</span><span class="mord mathdefault">L</span><span class="mopen">[</span><span class="mord mathdefault" style="margin-right:0.05017em;">B</span><span class="mord mathdefault" style="margin-right:0.08125em;">H</span><span class="mopen">(</span><span class="mord mathdefault" style="margin-right:0.03588em;">v</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">1</span><span class="mclose">]</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">1</span></span></span></span></span></p>
<p>由此可得</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>T</mi><mi>O</mi><mi>T</mi><mi>A</mi><mi>L</mi><mo stretchy="false">[</mo><mi>B</mi><mi>H</mi><mo stretchy="false">(</mo><mi>v</mi><mo stretchy="false">)</mo><mo stretchy="false">]</mo><mo>=</mo><msup><mn>2</mn><mrow><mi>B</mi><mi>H</mi><mo stretchy="false">(</mo><mi>v</mi><mo stretchy="false">)</mo></mrow></msup><mo>−</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">TOTAL[BH(v)] = 2^{BH(v)} - 1
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathdefault" style="margin-right:0.13889em;">T</span><span class="mord mathdefault" style="margin-right:0.02778em;">O</span><span class="mord mathdefault" style="margin-right:0.13889em;">T</span><span class="mord mathdefault">A</span><span class="mord mathdefault">L</span><span class="mopen">[</span><span class="mord mathdefault" style="margin-right:0.05017em;">B</span><span class="mord mathdefault" style="margin-right:0.08125em;">H</span><span class="mopen">(</span><span class="mord mathdefault" style="margin-right:0.03588em;">v</span><span class="mclose">)</span><span class="mclose">]</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.0213299999999998em;vertical-align:-0.08333em;"></span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.938em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.05017em;">B</span><span class="mord mathdefault mtight" style="margin-right:0.08125em;">H</span><span class="mopen mtight">(</span><span class="mord mathdefault mtight" style="margin-right:0.03588em;">v</span><span class="mclose mtight">)</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">1</span></span></span></span></span></p>
<p>因此BH(V) 跟 TOTAL[V] 之间满足指数关系。又由<strong>性质4</strong>可知，树的黑高至少为这棵树的二分之一。 即 BH(V) &gt;= H(V) / 2，可得，对于根结点root而言。有</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>n</mi><mo>≥</mo><msup><mn>2</mn><mrow><mi>B</mi><mi>H</mi><mo stretchy="false">(</mo><mi>r</mi><mi>o</mi><mi>o</mi><mi>t</mi><mo stretchy="false">)</mo></mrow></msup><mo>−</mo><mn>1</mn><mo>=</mo><mo>&gt;</mo><mi>n</mi><mo>≥</mo><msup><mn>2</mn><mrow><mi>H</mi><mo stretchy="false">(</mo><mi>r</mi><mi>o</mi><mi>o</mi><mi>t</mi><mo stretchy="false">)</mo><mo>÷</mo><mn>2</mn></mrow></msup><mo>−</mo><mn>1</mn><mo>=</mo><mo>&gt;</mo><mi>n</mi><mo>+</mo><mn>1</mn><mo>≥</mo><msup><mn>2</mn><mrow><mi>H</mi><mo stretchy="false">(</mo><mi>r</mi><mi>o</mi><mi>o</mi><mi>t</mi><mo stretchy="false">)</mo><mo>÷</mo><mn>2</mn></mrow></msup><mo>=</mo><mo>&gt;</mo><mi>l</mi><mi>o</mi><msub><mi>g</mi><mn>2</mn></msub><mo stretchy="false">(</mo><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">)</mo><mo>≥</mo><mi>H</mi><mo stretchy="false">(</mo><mi>r</mi><mi>o</mi><mi>o</mi><mi>t</mi><mo stretchy="false">)</mo><mo>÷</mo><mn>2</mn><mo>=</mo><mo>&gt;</mo><mi>H</mi><mo stretchy="false">(</mo><mi>r</mi><mi>o</mi><mi>o</mi><mi>t</mi><mo stretchy="false">)</mo><mo>≤</mo><mn>2</mn><mo>⋅</mo><mi>l</mi><mi>o</mi><msub><mi>g</mi><mn>2</mn></msub><mo stretchy="false">(</mo><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">
n \geq 2^{BH(root)} - 1

=&gt; n \geq 2^{H(root) \div 2} - 1

=&gt; n + 1 \geq 2^{H(root) \div 2}

=&gt; log_2(n + 1) \geq H(root) \div 2

=&gt;  H(root) \leq 2 \cdot log_2(n + 1)

</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.7719400000000001em;vertical-align:-0.13597em;"></span><span class="mord mathdefault">n</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≥</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.0213299999999998em;vertical-align:-0.08333em;"></span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.938em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.05017em;">B</span><span class="mord mathdefault mtight" style="margin-right:0.08125em;">H</span><span class="mopen mtight">(</span><span class="mord mathdefault mtight" style="margin-right:0.02778em;">r</span><span class="mord mathdefault mtight">o</span><span class="mord mathdefault mtight">o</span><span class="mord mathdefault mtight">t</span><span class="mclose mtight">)</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">1</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span></span><span class="base"><span class="strut" style="height:0.5782em;vertical-align:-0.0391em;"></span><span class="mrel">&gt;</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.7719400000000001em;vertical-align:-0.13597em;"></span><span class="mord mathdefault">n</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≥</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.0213299999999998em;vertical-align:-0.08333em;"></span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.938em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.08125em;">H</span><span class="mopen mtight">(</span><span class="mord mathdefault mtight" style="margin-right:0.02778em;">r</span><span class="mord mathdefault mtight">o</span><span class="mord mathdefault mtight">o</span><span class="mord mathdefault mtight">t</span><span class="mclose mtight">)</span><span class="mbin mtight">÷</span><span class="mord mtight">2</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">1</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span></span><span class="base"><span class="strut" style="height:0.5782em;vertical-align:-0.0391em;"></span><span class="mrel">&gt;</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.66666em;vertical-align:-0.08333em;"></span><span class="mord mathdefault">n</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.78041em;vertical-align:-0.13597em;"></span><span class="mord">1</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≥</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.938em;vertical-align:0em;"></span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.938em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.08125em;">H</span><span class="mopen mtight">(</span><span class="mord mathdefault mtight" style="margin-right:0.02778em;">r</span><span class="mord mathdefault mtight">o</span><span class="mord mathdefault mtight">o</span><span class="mord mathdefault mtight">t</span><span class="mclose mtight">)</span><span class="mbin mtight">÷</span><span class="mord mtight">2</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span></span><span class="base"><span class="strut" style="height:0.5782em;vertical-align:-0.0391em;"></span><span class="mrel">&gt;</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathdefault" style="margin-right:0.01968em;">l</span><span class="mord mathdefault">o</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">g</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathdefault">n</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">1</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≥</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathdefault" style="margin-right:0.08125em;">H</span><span class="mopen">(</span><span class="mord mathdefault" style="margin-right:0.02778em;">r</span><span class="mord mathdefault">o</span><span class="mord mathdefault">o</span><span class="mord mathdefault">t</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">÷</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">2</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span></span><span class="base"><span class="strut" style="height:0.5782em;vertical-align:-0.0391em;"></span><span class="mrel">&gt;</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathdefault" style="margin-right:0.08125em;">H</span><span class="mopen">(</span><span class="mord mathdefault" style="margin-right:0.02778em;">r</span><span class="mord mathdefault">o</span><span class="mord mathdefault">o</span><span class="mord mathdefault">t</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">2</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">⋅</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathdefault" style="margin-right:0.01968em;">l</span><span class="mord mathdefault">o</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">g</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathdefault">n</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">1</span><span class="mclose">)</span></span></span></span></span></p>
<h3 id="与-avl-的比较"><a class="markdownIt-Anchor" href="#与-avl-的比较"></a> 与 avl 的比较</h3>
<p>两者都是经过优化的自平衡二叉树。有各自的自平衡算法，增删查效率都是log(n)但有一些区别。但从平衡性而言，AVL的平衡性更加严格，如下图所示情况。 红黑树允许较低的平衡性（但复杂度仍为log(n)）换取更少的自平衡操作。由于avl数平衡性高于红黑树，查询效率上会高于红黑树（但复杂度仍为log(n)）。红黑树算是比较「折衷」的平衡树方案，C++的STL中和JAVA的TreeMap&amp;HashMap都实现了红黑树以达到O(log(n)) 的插入删除的效果</p>
<style>
img {
margin:auto;
width:61.8%;
}
</style>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/structure/" rel="tag"># 数据结构</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2019/11/22/hello-world/" rel="prev" title="Hello World">
      <i class="fa fa-chevron-left"></i> Hello World
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/04/22/Leetcode-No-864-shortest-path-to-get-all-keys/" rel="next" title="Leetcode No.864 shortest path to get all keys.">
      Leetcode No.864 shortest path to get all keys. <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          
    <div class="comments" id="comments"></div>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#红黑树"><span class="nav-number">1.</span> <span class="nav-text"> 红黑树</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#性质"><span class="nav-number">1.1.</span> <span class="nav-text"> 性质</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#操作"><span class="nav-number">1.2.</span> <span class="nav-text"> 操作</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#旋转"><span class="nav-number">1.2.1.</span> <span class="nav-text"> 旋转</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#新增"><span class="nav-number">1.2.2.</span> <span class="nav-text"> 新增</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#删除"><span class="nav-number">1.2.3.</span> <span class="nav-text"> 删除</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#删除流程"><span class="nav-number">1.2.3.1.</span> <span class="nav-text"> 删除流程</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#删除后平衡操作"><span class="nav-number">1.2.3.2.</span> <span class="nav-text"> 删除后平衡操作</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#证明"><span class="nav-number">1.3.</span> <span class="nav-text"> 证明</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#与-avl-的比较"><span class="nav-number">1.4.</span> <span class="nav-text"> 与 avl 的比较</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Cyril Nee"
      src="https://blog-bucket-1300756499.cos.ap-chengdu.myqcloud.com/avatar.jpg">
  <p class="site-author-name" itemprop="name">Cyril Nee</p>
  <div class="site-description" itemprop="description">站在巨人的肩膀上。</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">11</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/cyrilney" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;cyrilney" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="/mailto:/cyrilnee2513@gmail.com" title="E-Mail → mailto:&#x2F;&#x2F;cyrilnee2513@gmail.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://instagram.com/cy.ril2513" title="Instagram → https:&#x2F;&#x2F;instagram.com&#x2F;cy.ril2513" rel="noopener" target="_blank"><i class="fa fa-fw fa-instagram"></i>Instagram</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://leetcode-cn.com/u/cyril-3" title="Leetcode → https:&#x2F;&#x2F;leetcode-cn.com&#x2F;u&#x2F;cyril-3" rel="noopener" target="_blank"><i class="fa fa-fw fa-cubes"></i>Leetcode</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Cyril Nee</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a>
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">Theme – <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a>
  </div>

        
<div class="busuanzi-count">
  <script async src="/js/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="Total Visitors">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="Total Views">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








        
      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/motion.js"></script>
<script src="/js/schemes/pisces.js"></script>
<script src="/js/next-boot.js"></script>



  




  <script src="/js/local-search.js"></script>













  

  

  


<script>
NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
  var GUEST = ['nick', 'mail', 'link'];
  var guest = 'nick,mail,link';
  guest = guest.split(',').filter(item => {
    return GUEST.includes(item);
  });
  new Valine({
    el: '#comments',
    verify: false,
    notify: false,
    appId: 'I6PDwb2i2zmm5sosK0MSBIXj-gzGzoHsz',
    appKey: 'IjwGjHl0XISqFwV5zY11fyCI',
    placeholder: "every niceness reminds me of her.",
    avatar: 'mm',
    meta: guest,
    pageSize: '10' || 10,
    visitor: false,
    lang: 'zh-cn' || 'zh-cn',
    path: location.pathname,
    recordIP: false,
    serverURLs: ''
  });
}, window.Valine);
</script><!-- hexo-inject:begin --><!-- hexo-inject:end -->

</body>
</html>
